package org.sean.framework.context;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Optional;

/**
 * 级别配置信息
 *
 * @author xielei
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApplicationInfo {

    /**
     * 是否打印StatusInfo栈信息
     */
    private boolean statusExceptionTrace = true;

    /**
     * 是否已上线
     */
    private boolean release = false;

    /**
     * @return 是否已上线
     */
    public static boolean isReleased() {
        return getApplication().release;
    }


    /**
     * @return 是否打印StatusException栈信息
     */
    public static boolean showStatusExceptionTrace() {
        return getApplication().statusExceptionTrace;
    }

    /**
     * @return ApplicationInfo Bean
     */
    private static ApplicationInfo getApplication() {
        return Optional.ofNullable(SpringApplicationContext.getBean(ApplicationInfo.class))
                .orElseGet(ApplicationInfo::new);
    }


}
